package com.msjh.vueservice.controller;


import com.msjh.vueservice.common.R;
import com.msjh.vueservice.entity.EduTeacher;
import com.msjh.vueservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author byy
 * @since 2022-06-09
 */
@RestController
@RequestMapping("/vueservice/edu-teacher")
@CrossOrigin
public class EduTeacherController {


    @Autowired
    private EduTeacherService eduTeacherService;

    @GetMapping("/teachers")
    public R getAllTeachers(){
        return R.ok().data("teachers",eduTeacherService.getAllTeachers());
    }


    @GetMapping("/deleteTeacherById")
    public R deleteTeacherById(Integer id){
        boolean result = eduTeacherService.removeById(id);
        if(result){
            return R.ok();
        }else{
            return R.error();
        }

    }

    @PostMapping("/addTeacher")
    public R addTeacher(@RequestBody EduTeacher teacher){
        boolean result = eduTeacherService.save(teacher);
        if(result){
            return R.ok();
        }else{
            return R.error();
        }

    }

    @GetMapping("/findTeacherById/{id}")
    public R findTeacherById(@PathVariable  Integer id){
        EduTeacher byId = eduTeacherService.getById(id);
        return R.ok().data("items",byId);
    }

    @PostMapping("/updateTeacher")
    public R updateTeacher(@RequestBody EduTeacher teacher){
        boolean result = eduTeacherService.updateById(teacher);
        if(result){
            return R.ok();
        }else{
            return R.error();
        }

    }
}

